package com.crm.CLdriving.controller;


import java.util.List;

import javax.validation.Valid;

import com.crm.CLdriving.common.PageResponse;
import com.crm.CLdriving.dto.PageReq.PageNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.req.StudentDelectReqDto;
import com.crm.CLdriving.dto.req.StudentInsertReqDto;
import com.crm.CLdriving.dto.req.StudentSelectByIdReqDto;
import com.crm.CLdriving.dto.req.StudentSelectReqDto;
import com.crm.CLdriving.dto.req.StudentUpdateReqDto;
import com.crm.CLdriving.dto.resp.StudentSelectRespDto;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.StudentPO;
import com.crm.CLdriving.service.StudentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

@Api(tags="学员信息管理")
@Controller
@Log4j2
@RequestMapping("student")
public class StudentController {
	
	@Autowired
	private StudentService studentService;
	
	@ApiOperation("学员信息录入接口") 
	@PostMapping(value="insert")
	@ResponseBody
	public BaseResponse<?> insert(@Valid @RequestBody StudentInsertReqDto studentInsertReqDto){
		log.info("c学员基本信息录入请求参数："+JSON.toJSONString(studentInsertReqDto));
		return studentService.insert(studentInsertReqDto);
	}
	
	
	@ApiOperation("学员基本信息查询接口")
	@PostMapping("selectJB")
	@ResponseBody
	public PageResponse<List<StudentSelectRespDto>> selectjb(@RequestBody PageNumber pageNumber){
		return studentService.selectJB(pageNumber);
	}
	
	//筛选框 查询
	@PostMapping("selectXQ")
	@ResponseBody
	@ApiOperation("学员详细信息查询接口")
	public BaseResponse<List<StudentSelectRespDto>> selectxq(@Valid @RequestBody StudentSelectReqDto studentSelectReqDto) {
		log.info("c学员详细信息查询请求参数为："+JSON.toJSONString(studentSelectReqDto));
		if ((studentSelectReqDto.getIdentityCard()==null || studentSelectReqDto.getIdentityCard()=="") &&
				(studentSelectReqDto.getName()==null || studentSelectReqDto.getName()=="")) {
			return BaseResponse.message(ResponseEnum.MYSXTJ);
		}
		return studentService.selectXQ(studentSelectReqDto);		
	}
	
	@PostMapping("selectById")
	@ResponseBody
	@ApiOperation("查询学员信息接口")
	public BaseResponse<StudentPO> selectById(@Valid @RequestBody StudentSelectByIdReqDto studentSelectByIdReqDto){
		return studentService.selectByid(studentSelectByIdReqDto);
	}
	
	@PostMapping("updateById")
	@ResponseBody
	@ApiOperation("更新学员信息接口")
	public BaseResponse<?> updateById(@Valid @RequestBody StudentUpdateReqDto studentUpdateReqDto) {
		log.info("c更新学员信息请求参数："+JSON.toJSONString(studentUpdateReqDto));
		return studentService.updateByid(studentUpdateReqDto);
	}
	
	
	@PostMapping("delectByID")
	@ResponseBody
	@ApiOperation("删除学员信息接口")
	public BaseResponse<?> delectByID(@Valid @RequestBody StudentDelectReqDto studentDelectReqDto) {
		log.info("删除学员信息请求参数："+JSON.toJSONString(studentDelectReqDto));
		return studentService.delectByid(studentDelectReqDto);
	}

}
